package com.ruoyi.job.service;


import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.utils.redis.RedisUtils;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 订单任务处理
 */
@Slf4j
@Service
public class OrderJobHandler {

    /**
     * 清除订单号和运单号累计次数
     */
    @XxlJob("clearOrderNo")
    public void clearOrderNo() {
        XxlJobHelper.log("清除订单和运单号累计次数 start");
        boolean deletedOrder = RedisUtils.deleteObject(CacheConstants.ORDER_SERIAL_KEY);
        if (deletedOrder) {
            XxlJobHelper.log("清除订单号累计次数成功");
        } else {
            XxlJobHelper.log("清除订单号累计次数失败");
        }
        boolean deletedWaybill = RedisUtils.deleteObject(CacheConstants.WAYBILL_SERIAL_KEY);
        if (deletedWaybill) {
            XxlJobHelper.log("清除运单号累计次数成功");
        } else {
            XxlJobHelper.log("清除运单号累计次数失败");
        }
        XxlJobHelper.handleSuccess("清除订单号和运单号累计次数成功");
    }
}
